package PTA;

import java.io.*;

public class Lx03 {
    public static void main(String[] args) {
        if(args.length != 2) {
            System.out.println("输入的参数不正确");
            System.exit(1);
        }
        File f1 = new File(args[0]);
        File f2 = new File(args[1]);
        if(!f1.exists()) {
            System.out.println("源文件不存在");
            System.exit(1);
        }
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            inputStream = new FileInputStream(f1);

        }catch(IOException e) {
            e.printStackTrace();
        }
        try {
            outputStream = new FileOutputStream(f2);
        }catch (IOException e) {
            e.printStackTrace();
        }
        if(inputStream != null && outputStream != null) {
            int tmp = 0;
            try {
                while((tmp = inputStream.read())!=-1) {
                    outputStream.write(tmp);
                }
                System.out.println("拷贝完成");
            }catch (IOException e) {
                e.printStackTrace();
                System.out.println("拷贝失败");
            }
            try {
                inputStream.close();
                outputStream.close();
            }catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
